
{{ template "layout.html" . }}

{{define "title"}}
    <title>文章列表页</title>
{{end}}

{{define "jsp"}}
    <script type="text/javascript" >
        window.onload=function(){
            $(".dels").click(function(){
                if(!confirm("是否删除？")){
                    return false
                }
            })
            $("#select").change(function(){
                $("#form").submit()
            })
            // #调用id，.调用class
        }
    </script>
{{end}}

{{define "main_body"}}
    <div class="main_body" id="main_body">
        <div class="breadcrub">
            当前位置：文章管理>文章列表
        </div>
        <div class="pannel">
            <span class="sel_label">请选择文章分类：</span>
           <form id="form" method="GET" action="/Article/ShowArticle">
                <select name="select" id="select" class="sel_opt">
                    <option >全部类型</option>

                    {{range .articletypes}}   
                    <!-- 此处使用了模板函数 -->
                            <option {{if eq .TypeName $.typename}} selected {{end}} >{{.TypeName}}</option>
                    {{end}}
                </select>
                <input type="submit" style="display:none">
            </form>
            <table class="common_table">
                <tr>
                    <th width="40%">文章标题</th>
                    <th width="10%">文章内容</th>
                    <th width="12%">添加时间</th>
                    <th width="12%">修改时间</th>
                    <th width="6%">阅读量</th>
                    <th width="6%">删除</th>
                    <th width="6%">编辑</th>
                    <th width="8%">文章类型</th>
                </tr>

                {{range $index,$val:= .articles}}
                <tr>
                    <td>{{$val.Title}}</td>
                    <td><a href="/Article/content?id={{$val.Id}}">查看详情</a></td>
                    <td>{{$val.CreateTime.Format "2006-01-02 15:04:05"}}</td>
                    <td>{{$val.UpdateTime.Format "2006-01-02 15:04:05"}}</td>
                    <td>{{$val.Count}}</td>
                    <td><a href="/Article/DeleteArticle?id={{$val.Id}}" class="dels">删除</a></td>
                    <td><a href="/Article/UpdateArticle?id={{$val.Id}}">编辑</a></td>
                    <td>{{$val.ArticleType.TypeName}}</td>
                    <!-- 跨表拿数据，需确保查询器增加了relatedsel函数 -->
                </tr>
                {{end}}
            </table>

            <ul class="pagenation">
                <li><a href="/Article/ShowArticle?pageIndex=1&select={{.typename}}">首页</a></li>
                {{if compare .EnableLast true}}
                <li><a href="/Article/ShowArticle?pageIndex={{.pageIndex | ShowLastPage}}&select={{.typename}}">上一页 </a> </li>
                {{else}}
                <li>上一页</li>
                {{end}}
                {{if compare .EnableNext true}}
                <li> <a href="/Article/ShowArticle?pageIndex={{.pageIndex | ShowNextPage}}&select={{.typename}}">下一页</a></li>
                {{else}}
                <li>下一页</li>
                {{end}}
                <li><a href="/Article/ShowArticle?pageIndex={{.pageCount}}&select={{.typename}}">末页</a></li>
                <li>共{{.count}}条记录/共{{.pageCount}}页/当前第{{.pageIndex}}页</li>
            </ul>
        </div>
    </div>
{{end}}